package com.tzeng.hist.manager;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.tzeng.hist.R;

public class TitleManager {
	/**
	 * app title工具,下面的常量用于setTiele方法中的flag，flag代表的是title中我要显示的iv
	 */

	public static final int BACK_ARROW = 1;// 返回（箭头）
	public static final int TITLE_NAME = 2;// 标题
	public static final int SET = 3; // me 界面的set
	public static final int SHARE = 4;// 分享
	public static final int MORE = 5;// 打开抽屉
	public static final int FILTER = 6;// 打开抽屉

	/**
	 * 
	 * @param from
	 *            当前的界面
	 * @param flags
	 *            title中需要显示的view
	 * @param title
	 *            title正中需要显示的文本
	 * @param to
	 *            需要调整到那一个界面
	 */
	public static void showTitle(final Activity from, int[] flags, Object title) {

		if (title instanceof Integer) {
			int title2 = (Integer) title;
			if (title2 > 0) {
				TextView tv = (TextView) from.findViewById(R.id.title_title_tv); 
				tv.setText(title2);
			}
		}
		if (title instanceof String) {
			TextView tv = (TextView) from.findViewById(R.id.title_title_tv); 
			tv.setText((String) title);
		}
		if (flags != null) {// 为null 是没有title bar
			for (int flag : flags) {
				switch (flag) {
				case SHARE: {
					ImageView iv = (ImageView) from
							.findViewById(R.id.title_share_iv);
					iv.setVisibility(View.VISIBLE);
					break;
				}

				case BACK_ARROW: {
					ImageView iv = (ImageView) from
							.findViewById(R.id.title_back_iv);
					iv.setVisibility(View.VISIBLE);
					iv.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							from.finish();
						}
					});
					break;
				}

				case SET: {
					ImageView iv = (ImageView) from
							.findViewById(R.id.title_set_iv);
					iv.setVisibility(View.VISIBLE);
					iv.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

						}
					});
					break;
				}
				case MORE: {
					ImageView iv = (ImageView) from
							.findViewById(R.id.title_drawer_iv);
					iv.setVisibility(View.VISIBLE);
					iv.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

						}
					});
					break;
				}
				case FILTER: {
					ImageView iv = (ImageView) from
							.findViewById(R.id.title_filter_iv);
					iv.setVisibility(View.VISIBLE);
					iv.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {

						}
					});
					break;
				}

				}
			}
		} else {
			ImageView iv = (ImageView) from.findViewById(R.id.title_set_iv);

			if (iv.isShown()) {
				iv.setVisibility(View.GONE);
			}
		}

	}

}
